<template>
  <div class="backgroundDiv" v-loading.fullscreen.lock="fullscreenLoading">
    <!--    <h2>北顾的自动ck获取</h2>-->
    <el-drawer
        title="公告"
        style="height: 1000px"
        :visible.sync="drawer"
        :direction="direction">
<!--      <svg t="1647166246355" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4413" width="20" height="20"><path d="M427.936 0h199.808l-22.544 696.048h-25.392v25.392h-101.584v-20.32h-25.392z" p-id="4414" fill="#d81e06"></path><path d="M538.544 907.616m-105.2 0a105.2 105.2 0 1 0 210.4 0 105.2 105.2 0 1 0-210.4 0Z" p-id="4415" fill="#d81e06"></path></svg>-->
      <div class="gongao">
<!--        <p class="gj">本网站可以一键获取京东 ck 并部署到服务自动运行</p>-->
<!--        <p class="gj">首先，输入手机号获取验证码，将验证码填入获取ck，</p>-->
<!--        <p class="gj">最后提交ck则可自动做京东任务</p>-->
<!--        <p class="gj">若已经获取了ck 可直接点最下方的提交COOKIE</p>-->

        <p class="gj">本网站的验证码登录已失效</p>
        <p class="gj">请自行抓包获取 ck 后 放到 cookie 提交</p>
        <p class="gj">安卓用户可以下载Hello JD 进行抓包</p>
        <p class="gj">https://wwe.lanzouj.com/ixYJB01gt9gh 密码:34ac</p>
        <p class="gj">ck 的格式为 pt_key=xxx;pt_pin=xxx;</p>
      </div>
    </el-drawer>
        <el-button @click="drawer = true" type="primary" style="margin-top: 10px;margin-bottom: 10px">
          公告
        </el-button>
    <div class="glass-container" id="glass">
      <section class="content">
        <h2>北顾的自动获取</h2>
        <el-row>
          <el-col>
            <span class="input input--minoru">
              <input class="input__field input__field--minoru" type="text" id="input-25" v-model="phone"
                     :disabled="true" maxlength="11" placeholder="看公告"/>
              <label class="input__label input__label--minoru" for="input-25">
                <span class="input__label-content input__label-content--minoru">{{ phoneText }}</span>
              </label>
            </span>
          </el-col>
          <el-col>
            <el-button @click="getapi" type="primary" round>获取验证码</el-button>
          </el-col>
          <el-col>
            <span class="input input--minoru">
              <input class="input__field input__field--minoru" type="text" id="input-26" v-model="code" :disabled="true" placeholder="看公告"/>
              <label class="input__label input__label--minoru" for="input-26">
                <span class="input__label-content input__label-content--minoru">{{ codeText }}</span>
              </label>
            </span>
          </el-col>
          <el-col>
            <el-button @click="getcookie" type="primary" round> 获取COOKIE</el-button>
          </el-col>
          <el-col>
            <span class="input input--minoru">
              <input class="input__field input__field--minoru" type="text" id="input-27" v-model="ck2"/>
              <label class="input__label input__label--minoru" for="input-27">
                <span class="input__label-content input__label-content--minoru">{{ cookieText }}</span>
              </label>
            </span>
          </el-col>
          <el-col>
            <el-button @click="POSTCOOKIE" type="primary" round> 提交COOKIE</el-button>
          </el-col>
        </el-row>
      </section>
    </div>
  </div>
</template>

<script>
import "../assets/js/classie"
import axios from "axios";

export default {
  name: 'HomeView',
  data() {
    return {
      //输入框字
      phoneText: '请输入手机号',
      codeText: '请输入验证码',
      cookieText: 'cookie',
      show: false,
      //加载效果
      fullscreenLoading: true,
      //抽屉效果
      drawer: false,
      direction: 'ttb',
      // 文本框禁用
      phonedisbaled: false,
      // 获取 ck
      phone: '',
      ck: '',
      ck2: '',
      gsalt: '',
      code: '',
      //  写入青龙
      token: '',
      jdid: '',
      remarks: '',
    }
  },
  methods: {
    getapi() {
      let phone = this.phone
      if (phone.length !== 11) {
        this.$message({
          type: "warning",
          message: "您输入的手机格式不正确"
        })
        return
      }
      this.$axios(`/jd/sendSms?phone=${phone}`)
          .then(res => {
            if (res.data.ok) {
              this.ck = res.data.data.ck
              this.gsalt = res.data.data.gsalt
              this.$message({
                type: "success",
                message: "验证码发送成功"
              });
              this.phonedisbaled = true
            } else {
              this.$message({
                type: "warning",
                message: res.data.msg
              });
            }
          })
    },
    getcookie() {
      let ck = this.ck
      let gsalt = this.gsalt
      let phone = this.phone
      let code = this.code
      if (!code) {
        this.$message({
          type: "warning",
          message: "请输入验证码"
        })
        return
      }
      this.$axios
          .post(`/jd/checkCode?phone=${phone}&code=${code}`, {
            ck: ck,
            gsalt: gsalt
          })
          .then(res => {
            if (res.data.ok) {
              this.ck2 = res.data.data.ck
              this.$message({
                type: "success",
                message: res.data.msg
              })
            } else {
              this.$message({
                type: "warning",
                message: res.data.msg
              })
            }
          })
      this.phonedisbaled = false
    },
    POSTCOOKIE() {
      let ck2 = this.ck2
      // 正则表达式
      let pattern = /pt_pin=[^.]+/
      if (!pattern.test(ck2)) {
        this.$message({
          type: "warning",
          message: "您输入的 ck 格式不正确"
        })
        return
      }
      let pt_pin = pattern.exec(ck2)[0]
      this.$axios
          .get(`http://121.5.104.125:5800/open/envs?searchValue=${pt_pin}`)
          .then(res => {
            if (res.data.data && res.data.data.length === 1) {
              this.jdid = res.data.data[0].id
              this.remarks = res.data.data[0].remarks
              this.$axios.put('http://121.5.104.125:5800/open/envs', {
                value: ck2,//变量值
                name: 'JD_COOKIE',
                remarks: this.remarks,//备注
                id: this.jdid
              })
              this.$message({
                type: "success",
                message: '更新ck成功'
              })
            } else {
              this.$axios
                  .post('http://121.5.104.125:5800/open/envs', [
                    {
                      value: ck2,
                      name: 'JD_COOKIE',
                      remarks: ""
                    }
                  ])
              this.$message({
                type: "success",
                message: "挂机成功"
              })
            }
          })
      this.phone = ''
      this.code = ''
      this.ck2 = ''
    }
  },
  mounted() {
    this.$axios
        .get('http://121.5.104.125:5800/open/auth/token?client_id=ORVXp_rNrM14&client_secret=J_YcXigZn4r9GIRNu3G7jPPY')
        .then(res => {
          if (res.data.code === 200) {
            this.token = `${res.data.data.token_type} ${res.data.data.token}`
            axios.defaults.headers.common['Authorization'] = this.token
          } else {
            this.$message({
              type: "warning",
              message: res.data.message
            })
          }
        })
    this.fullscreenLoading = false
  },

}
</script>
<style>
@import "../assets/css/component.css";
@import "../assets/css/demo.css";
@import "../assets/css/normalize.css";

* {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  /*margin-top: 5px;*/
  /*margin-bottom: 5px;*/
}

/* This was made with GlassGenerator.netlify.app */


.backgroundDiv {
  background: #acb6e5; /* fallback for old browsers */
  background: -webkit-linear-gradient(to right, #86fde8, #acb6e5); /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to right, #86fde8, #acb6e5); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

}

.gongao {
  text-align: center;
}

h2 {
  padding-top: 30px;
  padding-bottom: 30px;
}

.el-input {
  max-width: 375px;
}

.footer {
  width: 100%;
  height: 190px;
  bottom: 30px;
}

.study {
  position: fixed;
  width: 150px;
  left: 0;
}

</style>
